package cn.codeforfun.modules.user.list;

import cn.codeforfun.modules.user.list.table.ListTableModel;
import cn.codeforfun.shared.Borders;
import cn.codeforfun.shared.LookAndFeelUtils;
import lombok.Getter;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.swing.*;
import java.awt.*;

@Component
@Getter
public class ListFrame extends JFrame {
    JButton refreshButton;
    JTable listTable;
    ListTableModel listTableModel;

    @PostConstruct
    protected void prepareFrame() {
        initFrame();
        initComponents();
        pack();
    }

    protected void initFrame() {
        getRootPane().setBorder(Borders.createEmptyBorder());
        setTitle("main menu");
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setResizable(false);
        LookAndFeelUtils.setWindowsLookAndFeel();
        setLayout(new GridLayout(1, 2, 20, 20));
    }

    protected void initComponents() {
        refreshButton = new JButton("刷新");
        add(refreshButton);

        listTable = new JTable(listTableModel);
        listTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        add(listTable);
    }
}
